#include "Game.h"
#include "MenuState.h"
#include "PlayState.h"
#include "Timer.h"
#include <iostream>


// The frames per second
const int FRAMES_PER_SECOND = 30;

//Keep track of the current frame
int frame = 0;
    
//Whether or not to cap the frame rate
bool cap = true;

//The frame rate regulator
Timer fps;


int main(int argc, char* argv[])
{
	GameInst::Instance()->Init("test", 640, 480, 32, false);

	GameInst::Instance()->ChangeState(PlayState::Instance());

	while(GameInst::Instance()->Running())
	{
		fps.start();

		GameInst::Instance()->HandleEvents();
		GameInst::Instance()->Update();
		GameInst::Instance()->Draw();

		frame++;

		if( ( cap == true ) && ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) )
        {
            //Sleep the remaining frame time
            SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
        }
	}

	// Cleanup the engine
	GameInst::Instance()->Clean();

	return 0;
}